package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.MsActivityVo;
import org.dromara.nursing.domain.bo.MsActivityBo;
import org.dromara.nursing.service.IMsActivityService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 活动安排
 *
 * @author Xue
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/activity")
public class MsActivityController extends BaseController {

    private final IMsActivityService msActivityService;

    /**
     * 查询活动安排列表
     */
    @SaCheckPermission("nursing:activity:list")
    @GetMapping("/list")
    public TableDataInfo<MsActivityVo> list(MsActivityBo bo, PageQuery pageQuery) {
        return msActivityService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出活动安排列表
     */
    @SaCheckPermission("nursing:activity:export")
    @Log(title = "活动安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MsActivityBo bo, HttpServletResponse response) {
        List<MsActivityVo> list = msActivityService.queryList(bo);
        ExcelUtil.exportExcel(list, "活动安排", MsActivityVo.class, response);
    }

    /**
     * 获取活动安排详细信息
     *
     * @param activityId 主键
     */
    @SaCheckPermission("nursing:activity:query")
    @GetMapping("/{activityId}")
    public R<MsActivityVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long activityId) {
        return R.ok(msActivityService.queryById(activityId));
    }

    /**
     * 新增活动安排
     */
    @SaCheckPermission("nursing:activity:add")
    @Log(title = "活动安排", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MsActivityBo bo) {
        return toAjax(msActivityService.insertByBo(bo));
    }

    /**
     * 修改活动安排
     */
    @SaCheckPermission("nursing:activity:edit")
    @Log(title = "活动安排", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MsActivityBo bo) {
        return toAjax(msActivityService.updateByBo(bo));
    }

    /**
     * 删除活动安排
     *
     * @param activityIds 主键串
     */
    @SaCheckPermission("nursing:activity:remove")
    @Log(title = "活动安排", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] activityIds) {
        return toAjax(msActivityService.deleteWithValidByIds(List.of(activityIds), true));
    }
}
